home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / cups.postinst < prev    next >
Encoding:
Text File  |  2012-12-29  |  9.3 KB  |  269 lines

  1. #! /bin/sh
  2. # postinst script for cups
  3. #
  4. # see: dh_installdeb(1)
  5.  
  6. set -e
  7.  
  8. # summary of how this script can be called:
  9. #        * <postinst> `configure' <most-recently-configured-version>
  10. #        * <old-postinst> `abort-upgrade' <new version>
  11. #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  12. #          <new-version>
  13. #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  14. #          <failed-install-package> <version> `removing'
  15. #          <conflicting-package> <version>
  16. # for details, see /usr/doc/packaging-manual/
  17. #
  18. # quoting from the policy:
  19. #     Any necessary prompting should almost always be confined to the
  20. #     post-installation script, and should be protected with a conditional
  21. #     so that unnecessary prompting doesn't happen if a package's
  22. #     installation fails and the `postinst' is called with `abort-upgrade',
  23. #     `abort-remove' or `abort-deconfigure'.
  24.  
  25. # Debconf
  26. . /usr/share/debconf/confmodule
  27.  
  28. # Default Configuration file
  29. if [ -e /etc/default/cups ]; then
  30.     . /etc/default/cups
  31. fi
  32.  
  33. if [ "$1" = configure ]; then
  34.     # Set up lpadmin group.
  35.     if [ -z "`getent group lpadmin`" ]; then 
  36.     addgroup --system lpadmin
  37.     fi
  38.  
  39.     if [ -L /usr/share/ppd/cups-transitional-dir ]; then
  40.     rm -f /usr/share/ppd/cups-transitional-dir
  41.     fi
  42.     if [ -L /usr/share/cups/model/cups-included ]; then
  43.     rm -f /usr/share/cups/model/cups-included
  44.     fi
  45.     
  46.     # set up custom PPD directory
  47.     chown root:lpadmin /usr/share/ppd/custom 2>/dev/null || true
  48.     chmod 3775 /usr/share/ppd/custom 2>/dev/null || true
  49.  
  50.     # Generate raw MIME handling files if they don't already exist.
  51.     if [ ! -e /etc/cups/raw.types ]; then
  52.     cat >/etc/cups/raw.types <<EOF
  53. # This file was generated by the cups package.  You may change it, or
  54. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  55. # will be regenerated by the package scripts.
  56.  
  57. application/octet-stream
  58. EOF
  59.     fi
  60.     if [ ! -e /etc/cups/raw.convs ]; then
  61.     cat >/etc/cups/raw.convs <<EOF
  62. # This file was generated by the cups package.  You may change it, or
  63. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  64. # will be regenerated by the package scripts.
  65.  
  66. application/octet-stream    application/vnd.cups-raw    0    -
  67. EOF
  68.     fi
  69.  
  70.     # Set up raw printing of application/octet-stream if desired.
  71.     db_fget cupsys/raw-print changed
  72.     if [ "$RET" = "true" ]; then
  73.     mv /etc/cups/raw.convs /etc/cups/raw.convs-convert
  74.     db_get cupsys/raw-print
  75.     if [ "$RET" = "true" ]; then
  76.         sed 's/^\s*#\s*application/application/' \
  77.         < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  78.     else
  79.         sed 's/^application/#application/' \
  80.         < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  81.     fi
  82.     rm -f /etc/cups/raw.convs-convert
  83.     db_fset cupsys/raw-print changed false
  84.     fi
  85.     # Set up backends
  86.     db_get cupsys/backend && SELECTED=$RET
  87.     list=`echo $SELECTED | sed -e 's/, /,/g'`
  88.     save_IFS=$IFS
  89.     IFS=,
  90.     (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp dnssd)
  91.     for module in $list; do
  92.       ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  93.       if [ "$module" = "ipp" ]; then
  94.     ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
  95.       fi
  96.     done
  97.     IFS=$save_IFS
  98.  
  99.     # activate new backends on upgrades
  100.     db_fset cupsys/backend changed false
  101.     
  102.     # Resync Debconf database with real state
  103.     list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp dnssd; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
  104.     db_set cupsys/backend $list;
  105.  
  106.     if [ -f /etc/cups/classes.conf ]; then
  107.       chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf
  108.     fi
  109.     if [ -f /etc/cups/printers.conf ]; then
  110.       chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf
  111.     fi
  112.  
  113.     # symlink snakeoil SSL certificate if present
  114.     if [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \
  115.       -e /etc/ssl/private/ssl-cert-snakeoil.key -a \
  116.       -n "`getent group ssl-cert`" -a ! -e /etc/cups/ssl/server.crt \
  117.       -a ! -e /etc/cups/ssl/server.key -a ! -h /etc/cups/ssl/server.crt \
  118.       -a ! -h /etc/cups/ssl/server.key ]; then
  119.      ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt
  120.      ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key
  121.     fi 
  122.  
  123.     APP_PROFILE=/etc/apparmor.d/usr.sbin.cupsd
  124.     if [ -f "$APP_PROFILE" ]; then
  125.         # Add the local/ include
  126.         LOCAL_APP_PROFILE=/etc/apparmor.d/local/usr.sbin.cupsd
  127.  
  128.         test -e "$LOCAL_APP_PROFILE" || {
  129.             tmp=`mktemp`
  130.         cat <<EOM > "$tmp"
  131. # Site-specific additions and overrides for usr.sbin.cupsd.
  132. # For more details, please see /etc/apparmor.d/local/README.
  133. EOM
  134.             mkdir `dirname $LOCAL_APP_PROFILE` 2>/dev/null || true
  135.             mv -f "$tmp" "$LOCAL_APP_PROFILE"
  136.             chmod 644 "$LOCAL_APP_PROFILE"
  137.         }
  138.  
  139.         # Reload the profile, including any abstraction updates
  140.         if aa-status --enabled 2>/dev/null; then
  141.             apparmor_parser -r -T -W "$APP_PROFILE" || true
  142.         fi
  143.     fi
  144.  
  145.     # init.d priority transition
  146.     if dpkg --compare-versions "$2" le-nl "1.3.9-15"; then
  147.     for l in 2 3 4 5; do
  148.         old=/etc/rc${l}.d/S20cups
  149.         new=/etc/rc${l}.d/S50cups
  150.         if [ -e "$old" ] && [ ! -e "$new" ]; then
  151.         mv "$old" "$new"
  152.         fi
  153.     done
  154.     fi
  155.  
  156.     # Clear cache if we upgrade to 1.4.x
  157.     if dpkg --compare-versions "$2" lt-nl "1.4.1-5"; then
  158.     rm /var/cache/cups/* 2> /dev/null || :
  159.     fi
  160.  
  161.     # Manage printcap file and associated symlinks
  162.     if [ -e /etc/cups/cupsd.conf ]; then
  163.     if [ -e /etc/printcap.cups ]; then
  164.         rm -f /etc/printcap.cups
  165.     fi
  166.     if [ -L /etc/printcap -a ! -e /etc/printcap ]; then
  167.         rm -f /etc/printcap
  168.     fi
  169.  
  170.     printcap_file=`egrep '^Printcap ' /etc/cups/cupsd.conf | awk '{print $2}' | tail -n 1`
  171.     if [ -z "$printcap_file" ]; then
  172.         printcap_file=/var/run/cups/printcap
  173.     fi
  174.     if [ ! -e /etc/printcap -a -e $printcap_file ]; then
  175.         ln -s $printcap_file /etc/printcap
  176.     fi
  177.     fi
  178.  
  179.     # Clean up after some broken cups-pdf versions
  180.     if dpkg --compare-versions "$2" lt-nl "1.4.4-1"; then
  181.     chmod 755 /usr/lib/cups/backend /usr/lib/cups/backend-available
  182.     fi
  183.  
  184.     # Create default cupsd.conf if it doesn't exist
  185.     if [ ! -r /etc/cups/cupsd.conf ]; then
  186.         if dpkg --compare-versions "$2" le "1.4.4-7+squeeze2~" && [ -e /etc/cups/cupsd.conf.conffile-bak ]; then
  187.             # Move cupsd.conf back as it is now a non-conffile
  188.             mv /etc/cups/cupsd.conf.conffile-bak /etc/cups/cupsd.conf
  189.         else
  190.             cp /etc/cups/cupsd.conf.default /etc/cups/cupsd.conf
  191.         fi
  192.     fi
  193. fi
  194.  
  195. # Automatically added by dh_installinit
  196. if [ -x "/etc/init.d/cups" ]; then
  197.     update-rc.d cups start 50 2 3 4 5 . stop 80 1 . >/dev/null
  198.     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  199.         invoke-rc.d cups start || exit $?
  200.     else
  201.         /etc/init.d/cups start || exit $?
  202.     fi
  203. fi
  204. # End automatically added section
  205. # Automatically added by dh_usrlocal
  206. if [ "$1" = configure ]; then
  207. (
  208.     while read line; do
  209.         set -- $line
  210.         dir="$1"; mode="$2"; user="$3"; group="$4"
  211.         if [ ! -e "$dir" ]; then
  212.             if mkdir "$dir" 2>/dev/null; then
  213.                 chown "$user":"$group" "$dir"
  214.                 chmod "$mode" "$dir"
  215.             fi
  216.         fi
  217.     done
  218. ) << DATA
  219. /usr/local/share 2775 root staff
  220. /usr/local/share/ppd 2775 root staff
  221. DATA
  222. fi
  223. # End automatically added section
  224.  
  225.  
  226. # Do the following only if CUPS is running and the needed CUPS tools
  227. # are available
  228. if [ "$1" = configure ] && \
  229.     which lpstat > /dev/null 2>&1 && \
  230.     which lpinfo > /dev/null 2>&1 && \
  231.     which lpadmin > /dev/null 2>&1 && \
  232.     LC_ALL=C lpstat -h /var/run/cups/cups.sock -r | grep -v not > /dev/null 2>&1; then
  233.     # Update the PPD files of all already installed print queues
  234.     driverregexp='lsb/usr/cups-included/|drv:///sample.drv/'
  235.     gennicknameregexp='s/,\s*\d+\.\d+[\d\.]*$//i'
  236.     [ ! -z "$gennicknameregexp" ] && \
  237.     gennicknameregexp="; $gennicknameregexp"
  238.     gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
  239.     tempfiles=
  240.     trap 'rm -f $tempfiles; exit 0' 0 HUP INT QUIT ILL ABRT PIPE TERM
  241.     tmpfile1=`mktemp -t updateppds.XXXXXX`
  242.     tempfiles="$tempfiles $tmpfile1"
  243.     lpinfo -h /var/run/cups/cups.sock -m | grep -E $driverregexp > $tmpfile1
  244.     cd /etc/cups/ppd
  245.     for ppd in *.ppd; do
  246.     [ -r "$ppd" ] || continue
  247.     queue=${ppd%.ppd}
  248.     lpstat -h /var/run/cups/cups.sock -p "$queue" >/dev/null 2>&1 || continue
  249.     nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'`
  250.     lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
  251.     ppdfound="0"
  252.     englishppduri=""
  253.     tmpfile2=`mktemp -t updateppds.XXXXXX`
  254.     tempfiles="$tempfiles $tmpfile2"
  255.     cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -i "$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
  256.     while read newppduri; do
  257.         [ "$ppdfound" = "0" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $newppduri 2>/dev/null || continue
  258.         newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
  259.         [ "$newlang" = "$lang" ] && ppdfound="1"
  260.         [ "$newlang" = "english" ] && englishppduri="$newppduri"
  261.     done < $tmpfile2
  262.     [ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin -h /var/run/cups/cups.sock -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1"
  263.     [ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2
  264.     done
  265. fi
  266.  
  267. db_stop
  268. exit 0
  269.